package com.koron.order.overhaul.service.impl;

import com.koron.common.core.util.CodeTools;
import com.koron.order.overhaul.bean.entity.OverhaulMajorFormWorker;
import com.koron.order.overhaul.mapper.OverhaulMajorFormWorkerMapper;
import com.koron.order.overhaul.service.OverhaulMajorFormWorkerService;
import com.koron.order.overhaul.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author twcao
 * @title: OverhaulMajorFormWorkerServiceImpl
 * @projectName GDH_EAM_V2
 * @description: 大修工单-表单-工作班成员实现类
 * @date 2021/10/817:20
 */
@Service
public class OverhaulMajorFormWorkerServiceImpl implements OverhaulMajorFormWorkerService {

    @Override
    public OverhaulMajorFormWorker queryById(SessionFactory factory, String id) {
        OverhaulMajorFormWorkerMapper mapper = factory.getMapper(OverhaulMajorFormWorkerMapper.class);
        return mapper.queryById(id);
    }

    @Override
    public List<OverhaulMajorFormWorker> queryList(SessionFactory factory, OverhaulMajorFormWorker formWorker) {
        OverhaulMajorFormWorkerMapper mapper = factory.getMapper(OverhaulMajorFormWorkerMapper.class);
        return mapper.queryList(formWorker);
    }

    @Override
    public int saveOrUpdate(SessionFactory factory, List<OverhaulMajorFormWorker> workers) {
        OverhaulMajorFormWorkerMapper mapper = factory.getMapper(OverhaulMajorFormWorkerMapper.class);
        CommonUtils.update(workers);
        workers.stream().forEach(worker -> worker.setId(StringUtils.isBlank(worker.getId()) ? CodeTools.getCode32() : worker.getId()));
        return mapper.saveOrUpdate(workers);
    }

    @Override
    public int deleteById(SessionFactory factory, String id) {
        OverhaulMajorFormWorkerMapper mapper = factory.getMapper(OverhaulMajorFormWorkerMapper.class);
        return mapper.deleteById(id);
    }

    @Override
    public int deleteByFormId(SessionFactory factory, String formId) {
        OverhaulMajorFormWorkerMapper mapper = factory.getMapper(OverhaulMajorFormWorkerMapper.class);
        return mapper.deleteByFormId(formId);
    }

    @Override
    public int deleteByOrderId(SessionFactory factory, String orderId) {
        OverhaulMajorFormWorkerMapper mapper = factory.getMapper(OverhaulMajorFormWorkerMapper.class);
        return mapper.deleteByOrderId(orderId);
    }
}
